//#include "../include/header.h"
#include "../include/Distributions.hpp"
#include "../include/utils.hpp"
#include "../include/Misc/Laplace.hpp"
#include "../include/Density.hpp"
//#include "../include/Gibbs.hpp"
#include "../include/Kernel.hpp"
#include "../include/Models/Likelihood.hpp"
#include "../include/Misc/EP.hpp"
#include "../include/Misc/EPst.hpp"
#include "../include/Misc/IWLS_Gelman.hpp"
#include "../include/simulate/rtnorm.hpp"
//#include "../include/SmcSampler.hpp"
#include "../include/Models/Prob_riemann.hpp"
#include "../include/Kernel_Riemann.hpp"
#include "../include/Resample.hpp"
#include "../include/Gibbs.hpp"
#include "../include/Particle.hpp"
#include "../include/KernelMALA.hpp"
#include "../include/PF/StochasticVol.hpp"
#include "../include/PF/SSM.hpp"
#include "../include/PF/PF.hpp"
#include "../include/PF/Likelihood.hpp"
#include "../include/MetropolisHastings.hpp"
#include "../include/PF/smc2stovol.hpp"


extern "C"{
void IBIS(int *M, int *T, int *p, double *Y, double *pX,double* thetap, int* m,double *res){
	
	mat X=vect2mat<double>(pX,T[0],p[0]);
	mat theta=vect2mat<double>(thetap,1,m[0]);
	mat mu(m[0],1);
	mu.fill(0.2);
	mat mi(m[0],1);
	mi.fill(0);
	mat Sig(m[0],m[0]);
	Sig.fill(0.1);
	Sig=diagmat(Sig);
	StoVol S(Y,X, T[0]);	
	mat s(m[0],m[0]);
	s.fill(0.1);
	s=diagmat(s);
	Resample::SysResample *R=new Resample::SysResample;
	PF<StoVol,Resample::SysResample> SVpf(M[0],&S,R,theta,T[0]);
	SVpf.Filter();
	double z=SVpf.Get_Z();
	cout << z;
	mat U=SVpf.GetMe();
	mat2vect<double>(U,T[0],1,res);
	Distribution::Gaussian *F=new Distribution::Gaussian(m[0],mu,Sig);
	Distribution::Gaussian *G=new Distribution::Gaussian(m[0],mi,s);
	SSlik::Likelihood<StoVol> Lik(&S,(int)theta.n_cols);
	smc2model<StoVol> SMC2(Y,X,F,T[0]);
	Kernel_MH<smc2model<StoVol>,Distribution::Gaussian> *K=new Kernel_MH<smc2model<StoVol>,Distribution::Gaussian>(&SMC2,G);
	Particle<Kernel_MH<smc2model<StoVol>,Distribution::Gaussian>,Resample::SysResample,Density::GeomBridge> P(K,R,&SMC2,(int)(M[0]),F);
	P.Filter();
	MHRW<SSlik::Likelihood<StoVol>,Distribution::Gaussian>	MK(&Lik,G,40000,theta);
	//MK();	
}
}
